package com.shop.zkmall.app.utils;

import com.shop.zkmall.app.service.a.ICereBuyerMerchantService;
import com.shop.zkmall.app.service.buyer.CereBuyerReceiveService;
import com.shop.zkmall.commons.domain.buyer.CereBuyerUser;
import jakarta.servlet.http.HttpServletRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

@Component
public  class  LoginHelper {

    @Autowired
    private CereBuyerReceiveService cereBuyerReceiveService;
    @Autowired
    private ICereBuyerMerchantService cereBuyerMerchantService;



    /**
     * 获取当前登录用户ID
     * @return
     */
    public static Long getUserId(){
        //获取HttpServletRequest
        HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
        CereBuyerUser user = (CereBuyerUser) request.getAttribute("user");
        return user.getBuyerUserId();
    }

    /**
     * 获取店铺id
     * @return
     */
    public Long getShopId(){
        //获取HttpServletRequest
        HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
        CereBuyerUser user = (CereBuyerUser) request.getAttribute("user");
        Long shopId = cereBuyerMerchantService.selShopId(user.getBuyerUserId());
        return user.getBuyerUserId();
    }

}
